package com.example.userservice.novel.entity;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 小说结构实体
 */
public class NovelStructure {

    private Long id;
    private String novelName;          // 小说名称
    private String theme;              // 核心主题
    private List<SimpleCharacter> mainCharacters; // 主要角色
    private String plotOutline;        // 故事大纲
    private String worldSetting;       // 世界观设定
    private String writingStyle;       // 写作风格建议
    private String rawResponse;        // AI原始回复
    private Date generatedAt;          // 生成时间

    
    public NovelStructure() {
        this.mainCharacters = new ArrayList<>();
        this.generatedAt = new Date();
    }

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    // Getter方法
    public String getNovelName() {
        return novelName;
    }

    public String getTheme() {
        return theme;
    }

    public List<SimpleCharacter> getMainCharacters() {
        return mainCharacters;
    }

    public String getPlotOutline() {
        return plotOutline;
    }

    public String getWorldSetting() {
        return worldSetting;
    }

    public String getWritingStyle() {
        return writingStyle;
    }

    public String getRawResponse() {
        return rawResponse;
    }

    public Date getGeneratedAt() {
        return generatedAt;
    }

    // Setter方法
    public void setNovelName(String novelName) {
        this.novelName = novelName;
    }

    public void setTheme(String theme) {
        this.theme = theme;
    }

    public void setMainCharacters(List<SimpleCharacter> mainCharacters) {
        this.mainCharacters = mainCharacters;
    }

    public void setPlotOutline(String plotOutline) {
        this.plotOutline = plotOutline;
    }

    public void setWorldSetting(String worldSetting) {
        this.worldSetting = worldSetting;
    }

    public void setWritingStyle(String writingStyle) {
        this.writingStyle = writingStyle;
    }

    public void setRawResponse(String rawResponse) {
        this.rawResponse = rawResponse;
    }

    public void setGeneratedAt(Date generatedAt) {
        this.generatedAt = generatedAt;
    }

    // 转换为Entity
    public NovelStructureEntity toEntity() {
        NovelStructureEntity entity = new NovelStructureEntity();
        entity.setNovelName(this.novelName);
        entity.setTheme(this.theme);
        entity.setPlotOutline(this.plotOutline);
        entity.setWorldSetting(this.worldSetting);
        entity.setWritingStyle(this.writingStyle);
        entity.setRawResponse(this.rawResponse);
        entity.setGeneratedAt(this.generatedAt);
//        entity.setGenre(this.genre);

        // 转换角色
        if (this.mainCharacters != null) {
            List<CharacterEntity> characterEntities = this.mainCharacters.stream()
                    .map(character -> {
                        CharacterEntity characterEntity = new CharacterEntity();
                        characterEntity.setName(character.getName());
                        characterEntity.setIdentity(character.getIdentity());
                        characterEntity.setPersonality(character.getPersonality());
                        characterEntity.setGoal(character.getGoal());
                        characterEntity.setGrowth(character.getGrowth());
                        characterEntity.setNovelStructure(entity);
                        return characterEntity;
                    })
                    .collect(Collectors.toList());
            entity.setCharacters(characterEntities);
        }

        return entity;
    }
}